package org.jeecg.config.uass;

import com.ccb.uass.client.bs.conf.Config;
import com.ccb.uass.client.bs.conf.IConfig;
import com.ccb.uass.client.bs.validation.ServiceTicketValiator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chensherun on 2022/1/25.
 * @version 1.0
 */
@Configuration
public class UassBeanConfig {

    @Bean
    public ServiceTicketValiator serviceTicketValiator(IConfig uassConfig) {
        ServiceTicketValiator serviceTicketValiator = ServiceTicketValiator.init(uassConfig);
        return serviceTicketValiator;
    }

    @Bean
    public IConfig uassConfig(UassProperties uassProperties) {
        Config defaultConfig = new Config();
        defaultConfig.setLoginUrl(uassProperties.getLoginUrl());
        defaultConfig.setLogoutUrl(uassProperties.getLogoutUrl());
        defaultConfig.setAppCode(uassProperties.getAppCode());
        defaultConfig.setValidaUrl(uassProperties.getValidaUrl());
        defaultConfig.setAppUrl(uassProperties.getAppUrl());
        defaultConfig.setExclude(uassProperties.getExclude());
        defaultConfig.setCheckSession(uassProperties.getCheckSession());
        defaultConfig.setAuthKey(uassProperties.getAuthKey());
        defaultConfig.setChannel(uassProperties.getChannel());
        defaultConfig.setConnectionTimeOut(Integer.valueOf(uassProperties.getConnectionTimeOut() != null ? uassProperties.getConnectionTimeOut() : "5000"));
        defaultConfig.setSoTimeOut(Integer.valueOf(uassProperties.getSoTimeOut() != null ? uassProperties.getSoTimeOut() : "5000"));
        defaultConfig.setDeployserverip(uassProperties.getDeployserverip());
        defaultConfig.setCryptoType(uassProperties.getCryptoType());
        defaultConfig.setHttpsTrust(uassProperties.getHttpsTrust());
        defaultConfig.setSameServerRetry(uassProperties.getSameServerRetry());
        defaultConfig.setLoginPageUrl(uassProperties.getLoginPageUrl());
        return defaultConfig;
    }
}
